package com.gulimall.search.controller;

import com.guli.common.utils.R;
import com.guli.common.vo.SkuEsModel;
import com.gulimall.search.searchImpl.SearchImpl;
import com.gulimall.search.vo.SearchParam;
import com.gulimall.search.vo.SearchResponse;
import com.gulimall.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;

/**
 * @author: 朱财艺
 * @date : 2022/01/08
 * @Description:
 */
@Controller
public class SearchController {

    @Autowired
    private SearchImpl search;

    @GetMapping(value = {"/","search.html"})
    public String index(SearchParam searchParam, Model model, HttpServletRequest request) throws IOException {
       /* searchParam.setKeyword("华为");
        *//*** 价格区间
         400_1900
         400_ 大于400
         _2000 小于2000
         * *//*
        searchParam.setSkuPrice("2000_8000");
        ArrayList<Long> longs = new ArrayList<>();
        longs.add(2L);
        longs.add(3L);
        searchParam.setBrandId(longs);
        searchParam.setCatalog3Id(225L);//分类id
        //属性
        ArrayList<String> strings = new ArrayList<>();
        strings.add("4_钛空银:流光幻镜:霓影紫");
        strings.add("2_2020:2021");
        searchParam.setAttrs(strings);*/
        SearchResult searchResult = search.getSearchResult1(searchParam);
        model.addAttribute("result",searchResult);
        return "search1";
    }

    @PostMapping("up")
    @ResponseBody
    public R startUp(@RequestBody List<SkuEsModel> skuEsModel) throws IOException {
        R startup = search.startup(skuEsModel);
        return startup;

    }
}
